@echo on
set gaindir=%~dp0
if "%~1"=="" (
	set d=%cd%
) else (
	set d=%~1
)

if not exist "%d%" (
	@echo %d% doesn't exist, quit.
	goto end
)

pushd "%d%"
@echo on
for /R %%a in (*.mp3) DO (
	cls
	@echo.
	@echo Processing %%a...
	@echo.
	"%gaindir%\mp3gain.exe" /p /s r /a "%%a" >>%gaindir%\normalize.log
	rem undo %gaindir%\mp3gain.exe /u "%%a" >>%gaindir%\normalize.log
)
@echo off

popd

:end 
